
/* reload the parent */
function reloadParent(url){
    if(url != null && url != ''){
        window.parent.location= url;
        window.parent.Lightbox.close();
    }
}

/* reload the page */
function reload(url){
    if(url != null && url != ''){       
        window.location= url;
        window.parent.Lightbox.close();
    }
}

/* reload the page */
function reloadThis(){ 
    window.location.reload();
//window.parent.Lightbox.close();
}

/** disable the page */
function disableControls(){           
    $('.disabled').attr('disabled', 'disabled');   
}

function selectOption(select_id, option_val) {
    $('#'+select_id+' option:selected').removeAttr('selected');
    $('#'+select_id+' option[value='+option_val+']').attr('selected','selected');
}

function submitForm(options,v){
    if(v){
        var submitButton = options["button"];
        $("#hiddenButton").val($(submitButton).val());
        $("form:first").submit();
    }
}

/* load the page[url] to the id. */
function ajaxLoad(options,v){    
    if(v)
        loadPage(options["selector"],options["page"]);
}

function loadURL(options,v){
    if(v)
        window.location = options["url"];
}
/* load the page[url] to the id. */
function loadPage(selector,page){   
    if(typeof(Lightbox) != "undefined"){
        Lightbox.close();
    }
    showAjaxImage(selector);
    $(selector).load(page,function(){
        $(selector).fadeIn(1000);        
    });    
}
/* submit ajax form */
function submitAjaxForm(formId,selector,text) {
    $(formId).ajaxSubmit({
        target: selector
    });
    showAjaxImage(selector,text)
}

function showAjaxImage(selector,text){    
    if(text != null && text != undefined){
        text ="<b style='margin-left:20px;'>"+text+"</b>";
    }else{
        text = "";
    }
    //$(selector).html("<img src='"+path+"/images/common/ajax-loader.gif' alt='Processing..' style='text-align:center;position:absolute'/></img>"+text);
    $(selector).append("<img src='"+path+"/images/common/ajax-loader.gif' alt='Processing..' style='text-align:center;position:absolute'/></img>"+text);
}

function Confirm(message,fun,options,event){
    $.prompt(message,{
        buttons:{
            Yes:true,
            No:false
        },
        callback: function(v){           
            fun(options,v);
        }
    });
}

function Alert(message){
    $.prompt(message,{
        buttons:{
            Ok:true
        },
        callback: function(v){
        //func(v,arg1,arg2);
        }
    });
}

function currentDate(ele){  
    if($(ele).val() == ''){
        return;
    }
    var d1 = new Date($(ele).val());
    if(d1 == 'Invalid Date'){
        $(ele).val("");
        Alert(d1);
    }else{
        //alert(new Date($("#railCutOff").val()));
        var d2 = new Date();
        d2.setDate(d2.getDate() - 1);        
        if((d1.getTime() - d2.getTime()) < 0){
            $(ele).val("");
            Alert($(ele).attr("title") + " should not be past date.");
        }
    }
}

function uppercase(ele){
    var v = $(ele).val().toUpperCase();
    return $(ele).val(v)
}

function isNumber(v){
    return ! isNaN(v) && v != '';
}

function clearContent(parentSelector){
    if(Confirm("Are you sure, you want to clear the content ?"))
        $(parentSelector).find("input,textarea").val("");
}

/**
 * Select the element and unselected other element by matching 'selector'
 */
function oneSelected(ele, selector){
    if($(ele).attr("checked")){
        $(selector).attr("checked", false);
        $(ele).attr("checked", true);
    }
}

function parentExists(){
    return (parent.location == window.location)? false : true;
}